/**
 * 闪动Title
 */
plugor.FlashTitle = {
	doc : document,
	timer : null,
	isFlash : false,
	oldTitle : '',
	message : [ '新消息', 'New...' ],
	messageIndex : 1,
	millisec:800,
	flash : function(msg) {
		if (this.isFlash) {
			this.stop();// 先停止
		} else {
			this.oldTitle = this.doc.title;// 保存原来的title
		}
		this.isFlash = true;
		if (msg) {
			this.message[0] = msg;
			this.message[1] = this.getSpace(msg)
		}
		var _this = this;
		this.timer = setInterval(function() {
			_this._flash();
		}, this.millisec);
	},
	_flash : function() {
		this.messageIndex = this.messageIndex ? 0 : 1;
		this.doc.title = '【' + this.message[this.messageIndex] + '】'+this.oldTitle;
	},
	stop : function() {
		if (this.timer && this.isFlash){
			clearInterval(this.timer);
			this.doc.title = this.oldTitle;// 将title复原
			this.isFlash = false;
		}
	},
	getSpace : function(msg) {
		var n = msg.length;
		var s = '';
		var num = msg.match(/\w/g);
		var n2 = (num != null) ? num.length : 0;// 半角字符的个数
		n = n - n2; // 全角字符个数
		var t = parseInt(n2 / 2);
		if (t > 0) {// 两个半角替换为一个全角
			n = n + t;
		}
		s = (n2 % 2) ? ' ' : '';// 如果半角字符个数为奇数
		while (n > 0) {
			s = s + '　';// 全角空格
			n--;
		};
		return s;
	}
};